import QtQuick
import QtQuick.Controls

Rectangle {
    color: "lightgray"

    Component {
        id: com1
        Rectangle {
            width: 100
            height: 100
            color: "blue"
            
            Text {
                anchors.centerIn: parent
                text: "This is Component"
                color: "white"
            }
        }
    }

    Column {
        anchors.centerIn: parent
        spacing: 10

        Button {
            text: "加载Component组件"
            onClicked: loader2.sourceComponent = com1
        }

        Button {
            text: "卸载组件"
            onClicked: loader2.sourceComponent = null
        }

        Loader {
            id: loader2
            width: 300
            height: 300
        }
    }
}
